﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class WorkTimeN_WorkTimeOvertimeList : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            InitializeComponent();

            Master.DataSource = WMaster;
           
            MasterPage_MasterPage mpg = (MasterPage_MasterPage)this.Page.Master;
            mpg.HelpHref = "~/Help/WorkTime/员工加班列表.htm";
            mpg.PageName = "员工加班列表";
            mpg.PicUrl = "";
            mpg.IntiBar();
        }
        this.Master.SetWhereing += new Srvtools.SetWhereEventHandler(Master_SetWhereing);
        this.WebClientQuery1.Show(this.Panel1);
        if (!IsPostBack)
        {
            this.Master.SetWhere("");
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkTimeN_WorkTimeOvertimeList));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DataCompressed = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SWorkTime.View_WorkTime_Overtime";
        this.WMaster.ServerModify = false;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    void Master_SetWhereing(object sender, Srvtools.SetWhereArgs e)
    {
        //非管理员只能查看自已的单据
        if (Srvtools.CliUtils.fGroupID.IndexOf(System.Configuration.ConfigurationManager.AppSettings["FlowAdmin"].ToString()) == -1)
        {
            String wh = " WorkTime_Overtime.EmployeeId='" + Convert.ToInt32(Srvtools.CliUtils.fLoginUser).ToString() + "'";
            if (e.WhereStr.Trim() == "")
                e.WhereStr = wh;
            else
                e.WhereStr += " And " + wh;
        }
    }

    public string GetOverTimeRange(object StartHour, object StartMinute, object EndHour, object EndMinute)
    {
        if ((Convert.IsDBNull(StartHour) != true) && (Convert.IsDBNull(StartMinute) != true) && (Convert.IsDBNull(EndHour) != true) && (Convert.IsDBNull(EndMinute) != true))
        {
            return (string)StartHour + ":" + (string)StartMinute + "~" + (string)EndHour + ":" + (string)EndMinute;
        }
        else
        {
            return "";
        }
    }
    public override void DataBind()
    {
        wgvMaster.DataBind();
    }

    protected void WebNavigator1_Command(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "cmdAdd")
        {
            Response.Redirect("WorkTimeOvertime.aspx?FLOWFILENAME=FL\\WorkTimeOvertime&NAVMODE=Insert&FLNAVMODE=Submit");//&NAVMODE=Inset&FLNAVMODE=Submit
        }
        else if (e.CommandName == "cmdClientQuery")
        {
            string ss = this.ResolveUrl("..\\InnerPages\\FlowDesigner.aspx") + "?FLOWFILENAME=WorkTimeOvertime";
            Response.Write(" <script   language=javascript> window.open( '" + ss + " ','流程图','height=600,width=800,top=50,left=100,toolbar=no,menubar=no,scrollbars=yes, resizable=yes,location=no, status=no'); </script> ");
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        WebClientQuery1.Execute(Panel1);
        DataBind();
    }

    protected void btnClear_Click(object sender, EventArgs e)
    {
        WebClientQuery1.Clear(Panel1);
        Master.DataBind();
        wgvMaster.DataBind();
    }

    protected void wgvMaster_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "del")
        {
            string[] c = e.CommandArgument.ToString().Split(',');
            /*
             * 0、table 
             * 1、PK
             * 2、id
             * 3、WorkTime_AddUp where 
             * 4、WorkTime_OverTime2Rest where 
             * 5、WorkTime_YearHoliday where
             */
            object[] objParam = new object[]{"WorkTime_Overtime","OvertimeId",c[0]," Wtype='15' and SheetId=" + c[0],
                (c[1] != "1" ? " 1=0" : " DataType=2 and SheetId=" + c[0] + " and CAST(ORTimes as numeric)>=0"),
                " 1=0"};
            object[] myRet = Srvtools.CliUtils.CallMethod("SWorkTime", "InvalidWorkOnForm", objParam);

            ClientScript.RegisterStartupScript(GetType(), "", "alert('作废成功！');location.href='" + Request.Url.ToString() + "'", true);
        }
    }

    protected void wgvMaster_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DataRowView drv = (DataRowView)e.Row.DataItem;

            ImageButton imb = (ImageButton)e.Row.FindControl("del");
             if (drv["FlowFlag"].ToString() == "X" || drv["FlowFlag"].ToString() == "")//&&
           // Srvtools.CliUtils.fGroupID.IndexOf(System.Configuration.ConfigurationManager.AppSettings["FlowAdmin"].ToString()) != -1)
            {
                imb.CommandArgument = drv["OvertimeId"].ToString() + "," + drv["Repay"].ToString();
                imb.CommandName = "del";
                imb.Attributes.Add("onclick", "return confirm('确认作废加班单" + drv["OvertimeId"].ToString() + " ？')");
            }
            else
            {
                imb.Visible = false;
            }
        }
    }
}
